#include <stdio.h>

/*
 * 数字转成字符串
 */

void i_c_c()
{
    int num = 1234;
    char result[32] = {0};
    int bit = 0;
    
    bit = num / 1000;
    printf("bit = %d %d\n", bit, 1234 % 1000);  // 1 234
    result[0] = bit + '0';

    bit = num / 100 % 10;
    result[1] = bit + '0';

    bit = num / 10 % 10;
    result[2] = bit + '0';

    bit = num % 10;
    result[3] = bit + '0';

    printf("char result = %s\n", result);
   
}

void h_c_c()
{
    int num = 0xabcdef;
    char result[32] = {0};
    int bit = 0;

    bit = num >> 20;
    result[0] = bit + 'a' - 10;

    bit = num >> 16;
    bit &= 0x0f;
    result[1] = bit + 'a' - 10;

    bit = num >> 12;
    bit &= 0x0f;
    result[2] = bit + 'a' - 10;

    bit = num >> 8;
    bit &= 0x0f;
    result[3] = bit + 'a' - 10;

    bit = num >> 4;
    bit &= 0x0f;
    result[4] = bit + 'a' - 10;

    bit = num >> 0;
    bit &= 0x0f;
    result[5] = bit + 'a' - 10;

    printf("hex result = %s\n", result);
}

void main()
{
    char a = '0';

    printf("a = %d = %c\n", a, a);   // a = 48 = 0

    a = 1;
    printf("a = %d = %c\n", a, a);   // a = 1 = 

    a = 49;
    printf("a = %d = %c\n", a, a);   // a = 49 = 1 

    i_c_c();
    h_c_c();
}
